/*==========================pay 员工接口==============================*/
import Ajax from './apiAjax';
export  default {
  state:{
    persons:{
      list:null,
      pb:null,
    },
    personBasicInfo:null,
    initAddPersonData:null,
    initUpdatePersonData:null,
  },
  mutations:{
    setPersons(state,data){
      state.persons={
        list:data.data.personInfo,
        pb:data.pb
      }
    },
    setPersonBasicInfo(state,data){
      state.personBasicInfo = data.data;
    },
    setInitAddPerson(state,data){
      state.initAddPersonData = data.data;
    },
    setInitUpdatePerson(state,data){
      state.initUpdatePersonData = data.data;
    }
  },
  actions:{
    /**
     * 查询员工列表
     * @param commit
     * @param paramData {...pb}
     * @returns {Promise}
     */
    getPersons({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/personInfo/getPersonList.do',
          data:paramData,
          success:function (data) {
            commit('setPersons',data);
            resolve();
          }
        })
      })
    },
    /**
     *查询员工基本信息
     * @param commit
     * @param paramData {personId:123}
     * @returns {Promise}
     */
    getPersonBasicInfo({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/personInfo/getPersonBasicInfo',
          data:paramData,
          success:function (data) {
            commit('setPersonBasicInfo',data);
            resolve();
          }
        })
      })
    },
    /**
     *添加员工初始化
     * @param commit
     * @param paramData
     * @returns {Promise}
     */
    initAddPerson({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/personInfo/addPersonInit',
          data:paramData,
          success:function (data) {
            commit('setInitAddPerson',data);
            resolve();
          }
        })
      })
    },
    /**
     * 添加员工
     * @param commit
     * @param paramData {...personObj}
     * @returns {Promise}
     */
    savePerson({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/personInfo/addPerson',
          data:JSON.stringify(paramData),
          contentType: "application/json;charset=UTF-8",
          success:function (data) {
            resolve();
          }
        })
      })
    },
    initUpdatePerson({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/personInfo/editPersonInfo',
          data:paramData,
          success:function (data) {
            commit('setInitUpdatePerson',data);
            resolve();
          }
        })
      })
    },
  /*  /!**
     * 更新员工头像
     * *!/
    uploadHeadImg:({commit},paramData) => {
      return new Promise((resolve, reject) => {
        console.log(paramData)
        Ajax({
          url:'/personInfo/uploadHeadImg',
          data:paramData,
          dataType:'json',
          type:'post',
          processData: false,
          contentType: false,
          success:function (data) {
            resolve();
          }
        })
      })
    },*/
  },
  getters: {
    personList: (state, getters) => {
      return state.persons.list;
    },
    personListPb: (state, getters) => {
      return state.persons.pb;
    },
    personBasicInfo: (state, getters) => {
      return state.personBasicInfo;
    },
    initAddPersonData: (state, getters) => {
      return state.initAddPersonData;
    },
    initUpdatePersonData: (state, getters) => {
      return state.initUpdatePersonData;
    },
  }
}
